#include<iostream>
#include <string>
#include <queue>
#define Maxsize 50
using namespace std;
typedef struct node{
    int data;
    struct node *lchild;
    struct node *rchild;
}BTNode;
BTNode *trans(string a,int i,int maxsize);
int WeightPathLength(BTNode* FBT,int h);
int GetHeight(BTNode *BT);
int sum=0;
int main(){
	int maxsize,h=0;
	BTNode *BT;
	string str;
	cin>>str;
	maxsize=str.size();
	BT=trans(str,1,maxsize);
	WeightPathLength(BT,h);
	cout<<sum;
	return 0;
	
}

int WeightPathLength(BTNode* FBT,int h){          
    if(!FBT){    
            return 0;    
    }    
    else{    
        if(FBT->lchild==NULL&&FBT->rchild==NULL ) {
        	sum=sum+FBT->data*h;
        	}              
            WeightPathLength(FBT->lchild,h+1);
			WeightPathLength(FBT->rchild,h+1);       
    }       
}    
BTNode *trans(string a,int i,int maxsize){
	BTNode *b;
	if(i>maxsize-1) return NULL;
	if(a[i]=='#') return NULL;
	b=new BTNode;
	b->data=a[i]-'0';
	b->lchild=trans(a,2*i,maxsize);
	b->rchild=trans(a,2*i+1,maxsize);
	return b;
}
